/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package minValue;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.dom4j.*;
import org.dom4j.io.SAXReader;

/**
 *
 * @author richard
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws DocumentException, IOException, Exception {

        ArrayList<String> as = new ArrayList<String>();
        as.addAll(Arrays.asList(args));
        SaveMoneyXML xx = new SaveMoneyXML();
        xx.ClearSavemoney();
        xx.Save();
      

        String fileS = "OK";
        for (String string : as) {
            SaveMoneyXML xmx = new SaveMoneyXML();

            SAXReader sr = new SAXReader();
            Document read = sr.read(new File(string + "savedata.xml"));
            Element rootElement = read.getRootElement();
            ArrayList<Element> ni = new ArrayList<Element>();
            Iterator nodeIterator = rootElement.elementIterator();
            while (nodeIterator.hasNext()) {
                Element item = (Element) nodeIterator.next();
                String file = item.attribute("yahoo").getValue();
                if (file.compareToIgnoreCase(fileS) != 0) {
                    xmx.SortLast(true);
                    xmx.ClearNode();
                    fileS = file;
                }
                xmx.AddElement(item);
            }
            xmx.SortLast(true);
            xmx.ClearNode();
            xmx.Save();
            xmx.DeleteFile(string);
        }
    }
}
